<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="test"></div>
    <script src="../lib/react.development.js"></script>
    <script src="../lib//react-dom.development.js"></script>
    <script src="../lib/babel.min.js"></script>
    <script type="text/babel">
        class MyComponent extends React.Component {
            state = {
                user: '',
                pwd: ''
            }
            saveFormData = (event) => {
                this.setState({ user: event.target.value })
            }
            submit = (event) => {
                const { user, pwd } = this
                // alert(`你的账号是:${this.user.value},你的密码是:${this.pwd.value}`)
                // console.log(`你的账号是:${this.user.value},你的密码是:${this.pwd.value}`)
                alert(`你的账号是:${user.value},你的密码是:${pwd.value}`)
                console.log(`你的账号是:${user.value},你的密码是:${pwd.value}`)
                event.preventDefault()
            }
            render() {
                return (
                    <div>
                        <form onSubmit={this.submit} onChange={this.saveUser} action="http://www.atguigu.com">
                            <input type="text" ref={c => this.user = c} placeholder="请输入内容" name="username" />
                            <br />
                            <input type="password" ref={c => this.pwd = c} onChange={this.savePwd} name="password" /><br />
                            <button>提交</button>
                            <h3>非受控组件:即现用现取(即用的时候就去取值)</h3>
                            <h3>受控组件:即将数据存储到state里面,然后要用的时候在从里面取值(类似于vue中的双向绑定)</h3>
                        </form>
                    </div>
                )
            }
        }
        ReactDOM.render(<MyComponent />, document.getElementById('test'))
    </script>
</body>

</html>